Skip to main content

Hydrix Chain — APIs & RPC

Hydrix Chain provides EVM-compatible JSON-RPC endpoints for developers to interact programmatically with the blockchain.
This section covers common RPC calls, validator failover, smart contract interaction, and best practices.


JSON-RPC API Endpoints​

Hydrix nodes run on:

  • https://chainfree.info:5010/validator/1
  • https://chainfree.info:5010/validator/2
  • https://chainfree.info:5010/validator/3
  • https://chainfree.info:5010/validator/4

All standard Ethereum JSON-RPC calls are supported.


Example: Connecting to Hydrix​

import { ethers } from "ethers";

const provider = new ethers.JsonRpcProvider("https://chainfree.info:8545");

Common RPC Calls​

1. Get Current Block Number​

const blockNumber = await provider.getBlockNumber();
console.log("Current block number:", blockNumber);

2. Get Balance of an Address​

const balance = await provider.getBalance("0xUSER_ADDRESS");
console.log("Balance (wei):", balance.toString());

3. Get Transaction Count (Nonce)​

const txCount = await provider.getTransactionCount("0xUSER_ADDRESS");
console.log("Transaction count:", txCount);

4. Get a Block by Number​

const block = await provider.getBlock("latest"); // or provide a number
console.log("Latest block:", block);

5. Get Transaction Details​

const txHash = "0xTRANSACTION_HASH";
const tx = await provider.getTransaction(txHash);
console.log("Transaction details:", tx);

6. Read Smart Contract State​

const contractAddress = "DEPLOYED_CONTRACT_ADDRESS";
const abi = ["function message() view returns (string)"];
const contract = new ethers.Contract(contractAddress, abi, provider);

const currentMessage = await contract.message();
console.log("Current message:", currentMessage);

7. Send a Transaction​

const signer = provider.getSigner("0xUSER_ADDRESS");
const contract = new ethers.Contract(contractAddress, abi, signer);

const tx = await contract.setMessage("Hello Hydrix!");
await tx.wait();
console.log("Transaction confirmed:", tx.hash);

Validator Failover​

Switch to another validator if one is under heavy load:

const validators = [
"https://chainfree.info:5010/validator/1",
"https://chainfree.info:5010/validator/2",
"https://chainfree.info:5010/validator/3",
"https://chainfree.info:5010/validator/4"
];

let provider = new ethers.JsonRpcProvider(validators[0]);

async function switchValidator(index) {
provider = new ethers.JsonRpcProvider(validators[index]);
console.log(`Switched to validator ${index + 1}`);
}

Event Monitoring​

Listen to contract events in real-time:

contract.on("MessageUpdated", (newMessage, event) => {
console.log("Message updated:", newMessage);
});

Best Practices​

  • Test all RPC calls and contracts on Hydrix testnet first
  • Keep private keys secure; never expose them in frontend code
  • Monitor validator endpoints and implement failover for reliability
  • Batch reads and use filters for large datasets to reduce RPC load